<?php

class Admin_Model_Admin extends Zend_Db_Table_Abstract
{
    protected $_name = 'admin';
    public function getAllData(){
    	$query = $this->select()
                        ->from($this->_name,array('adminId', 'username', 'status', 'email'))
                        ->where("adminId > 1");
    	return $this->fetchAll($query);
    }
    public function addData($username, $password, $status, $email){
    	$data = array('username' => $username, 'password' => md5($password), 'status' => $status, 'email' => $email);
        $idAdd = $this->insert($data);
        return $idAdd;
    }
    public function deleteData($adminId){
        $this->delete('adminId =' . (int)$adminId);  
    }
    public function updateData($adminId, $username, $password, $status, $email){
    	if($password && strlen($password) >= 6){
    		 $data = array('username' => $username ,'password' => md5($password), 'status' => $status, 'email' => $email);
    	}else{
    		 $data = array('username' => $username, 'status' => $status, 'email' => $email);
    	}
        return $this->update($data, 'adminId = ' . (int)$adminId);
    }

    public function getDataById ($adminId){
    	$query = $this->select()
                        ->from($this->_name, array('adminId', 'username', 'status','email'))
                        ->where('adminId = ?',(int)$adminId);
        return $this->fetchRow($query);
    }
    public function updatePass ($adminId, $password){
        $data['password'] = md5($password);
        return $this->update($data, 'adminId=' . (int)$adminId );
    }
    public function getDataByUsername($username){
        $query = $this->select()
            ->from($this->_name,array('adminId', 'username', 'password', 'status','email'))
            ->where('username = ?', $username);
        return $this->fetchRow($query);
    }
  
}

